package demo;

public class BNTree {

    static class TreeNode
    {
        private TreeNode left;
        private TreeNode right;
        private char val;
        public TreeNode(char val){
            this.val = val;
        }


    }

/*    public int getLeaveNum()
    {
        int tmp ;
        return tmp;
    }*/
    public TreeNode createNode(char val)
    {
        if(root == null)
        {
            TreeNode node = new TreeNode(val);
            root = node;
            return root;
        }
        TreeNode node = new TreeNode(val);
        return node;
    }
    public TreeNode root;

    //前序遍历
    public void preOrder(TreeNode root)
    {
        if(root == null)
        {
            return;
        }
        System.out.print((root.val)+" ");
        preOrder(root.left);
        preOrder(root.right);
    }

    //中序遍历
    public void inOrder(TreeNode root)
    {
        if(root == null)
        {
            return;
        }
        inOrder(root.left);
        System.out.print((root.val)+" ");
        inOrder(root.right);
    }

    //后序遍历
    public void postOrder(TreeNode root)
    {
        if(root == null)
        {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.print((root.val)+" ");
    }
    public static void main(String[] args) {
        BNTree Tree = new BNTree();
        //穷举法，创建一棵二叉树
        TreeNode A =  new TreeNode('a');
        TreeNode B =  new TreeNode('b');
        TreeNode C =  new TreeNode('c');
        TreeNode D =  new TreeNode('d');
        TreeNode E =  new TreeNode('e');
        A.left = B;
        B.left = C;
        B.right = D;
        A.right = E;

        System.out.print("前序遍历：");
        Tree.preOrder(A);

        System.out.print("中序遍历：");
        Tree.inOrder(A);

        System.out.print("后序遍历：");
        Tree.postOrder(A);
    }
}
